# pushbuttons.s
# pushbutton input functions
#
# connect4-nios2 project
#
#
.equ PUSHBUTTON_ADDR, 0xff1090

.data

.global PUSHBUTTON_EN_INT
.global PUSHBUTTON_CHECK_INT

.text

PUSHBUTTON_EN_INT:
	# enable pushbutton interrupts
	subi sp, sp, 4
	stw ra, 0(sp)
	
	movia r3, PUSHBUTTON_ADDR
	
	movi r2, 0b1001	# enable first and last buttons
	stwio r2, 8(r3)
	
	movi r2, 0x20	# 6th bit, IRQ 5
	WRCTL ctl3, r2
	
	ldw ra, 0(sp)
	addi sp, sp, 4
	ret
	
PUSHBUTTON_CHECK_INT:
	# check pushbutton interrupts - return keys pressed in r2
	subi sp, sp, 4
	stw ra, 0(sp)
	
	movia r3, PUSHBUTTON_ADDR
	
	ldwio r2, 0(r3)	# read buttons
	
	stwio r0, 12(r3)	# ack interrupt
	
	ldw ra, 0(sp)
	addi sp, sp, 4
	ret


#eof
